package com.factory.test.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.factory.test.base.MyApplication;


public class DataSaveUtil {

    private static DataSaveUtil dataSaveUtil;

    public static synchronized DataSaveUtil getInstance(){
        if(dataSaveUtil == null){
            dataSaveUtil = new DataSaveUtil();
        }
        return dataSaveUtil;
    }


    private SharedPreferences sharedPreferences;


    private DataSaveUtil(){
        sharedPreferences = MyApplication.getMyApplication().getSharedPreferences("appNewConfig", Context.MODE_PRIVATE);
    }

    /**
     * 重新登录的时候, 清空所有数据
     */
    public void empty(){
        sharedPreferences.edit().clear().commit();
    }


    public void saveBurn(boolean burnAll){
        //sharedPreferences.getBoolean("burnAll", false);
        sharedPreferences.edit().putBoolean("burnAll", burnAll).commit();
    }

    public boolean isRurn(){
        return sharedPreferences.getBoolean("burnAll", false);
    }

    public int getDesignIndex(){
        int defValue = 0;
        try {
            WindowManager wm = (WindowManager) MyApplication.getMyApplication().getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics outMetrics = new DisplayMetrics();
            wm.getDefaultDisplay().getRealMetrics(outMetrics);
            int widthPixel = outMetrics.widthPixels;
            int heightPixel = outMetrics.heightPixels;
            if(widthPixel > heightPixel){
                defValue = 1;
            }
        } catch (Exception e) {
            //throw new RuntimeException(e);
        }

        return sharedPreferences.getInt("AutoSizeDesign", defValue);
    }

    public void setDesignIndex(int index){
        sharedPreferences.edit().putInt("AutoSizeDesign", index).commit();
    }
}
